package com.lehecai.core.api.openapi;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.util.CoreDateUtils;

public class OpenAPIAppRecommend extends AbstractApiResultBean {
	
	public static final String QUERY_APP_IS_OPEN = "app_isopen";
	public static final String QUERY_APP_STATUS = "app_status";
	public static final String QUERY_APP_ID = "app_id";
	public static final String QUERY_APP_TYPE_RECOMMEND = "app_type";
	public static final String QUERY_SIGN = "sign";
	
	public static final String QUERY_SIGN_UPDATE = "1";//更新信息
	public static final String QUERY_SIGN_STATUS = "2";//审核
	
	public static final String SET_APP_NAME = "app_name";
	public static final String SET_APP_VERSION = "app_version";
	public static final String SET_APP_STATUS = "app_status";
	public static final String SET_APP_SIZE = "app_size";
	public static final String SET_APP_DOWNLOAD_URL = "app_down_url";
	public static final String SET_APP_PRICE = "app_price";
	public static final String SET_APP_TYPE_RECOMMEND = "app_type";
	public static final String SET_APP_IS_OPEN = "app_isopen";
	public static final String SET_APP_IS_FREE = "app_isfree";
	public static final String SET_APP_DESCRIBE = "app_describe";
	public static final String SET_APP_ICON = "app_icon";
	public static final String SET_APP_SORT = "app_sort";
	
	public static final String ORDER_APP_ID = "app_id";
	public static final String ORDER_TIME_ADD = "app_upload_time";
	public static final String ORDER_TIME_UPDATE = "app_updata_time";
	
	private long appId;					            //应用编号
	private String appName;				            //应用名称
	private String appVersion;			            //应用版本
	private String appSize;                         //应用大小
	private String appDownUrl;                      //应用下载地址
	private String appIcon;                         //应用图标
	private String appDescribe;			            //应用描述
	private OpenAPIAppRecommendFreeType appIsFree;	//是否免费标志（1=免费， 0=收费）
	private Double appPrice;                        //价格
	private YesNoStatus appStatus;	                //应用状态（1=通过审核， 0=没有通过审核 ）
	private OpenAPIAppRecommendType appType;        //应用类型（1=ios应用， 2=android应用）
	private Date createTime;				        //应用添加时间
	private Date updateTime;			            //应用更新时间
	private YesNoStatus appIsOpen;                  //应用推荐标志(1=开启， 0=关闭)
	private Integer appSort;                        //排序
	
	public static OpenAPIAppRecommend convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		OpenAPIAppRecommend openAPIApp = new OpenAPIAppRecommend();
		openAPIApp.setAppId(getLong(object, QUERY_APP_ID));
		openAPIApp.setAppName(getString(object, SET_APP_NAME));
		openAPIApp.setAppVersion(getString(object, SET_APP_VERSION));
		openAPIApp.setAppSize(getString(object, SET_APP_SIZE));
		openAPIApp.setAppDownUrl(getString(object, SET_APP_DOWNLOAD_URL));
		openAPIApp.setAppIcon(getString(object, SET_APP_ICON));
		openAPIApp.setAppDescribe(getString(object, SET_APP_DESCRIBE));
		openAPIApp.setAppIsOpen(YesNoStatus.getItem(getInt(object, SET_APP_IS_OPEN)));
		openAPIApp.setAppIsFree(OpenAPIAppRecommendFreeType.getItem(getInt(object, SET_APP_IS_FREE)));
		openAPIApp.setAppStatus(YesNoStatus.getItem(getInt(object, SET_APP_STATUS)));
		openAPIApp.setAppType(OpenAPIAppRecommendType.getItem(getInt(object, SET_APP_TYPE_RECOMMEND)));
		openAPIApp.setAppPrice(getDouble(object, SET_APP_PRICE));
		openAPIApp.setCreateTime(CoreDateUtils.parseDate(getString(object, ORDER_TIME_ADD), CoreDateUtils.DATETIME));
		openAPIApp.setUpdateTime(CoreDateUtils.parseDate(getString(object, ORDER_TIME_UPDATE), CoreDateUtils.DATETIME));
		openAPIApp.setAppSort(getInt(object, SET_APP_SORT));
		return openAPIApp;
	}
	
	public static List<OpenAPIAppRecommend> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<OpenAPIAppRecommend> list = new ArrayList<OpenAPIAppRecommend>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}
	
	public long getAppId() {
		return appId;
	}
	public void setAppId(long appId) {
		this.appId = appId;
	}
	public String getAppName() {
		return appName;
	}
	public void setAppName(String appName) {
		this.appName = appName;
	}

	public String getAppVersion() {
		return appVersion;
	}
	public void setAppVersion(String appVersion) {
		this.appVersion = appVersion;
	}

	public void setAppDescribe(String appDescribe) {
		this.appDescribe = appDescribe;
	}

	public String getAppDescribe() {
		return appDescribe;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}
	public String getAppSize() {
		return appSize;
	}

	public void setAppSize(String appSize) {
		this.appSize = appSize;
	}

	public String getAppDownUrl() {
		return appDownUrl;
	}

	public void setAppDownUrl(String appDownUrl) {
		this.appDownUrl = appDownUrl;
	}

	public String getAppIcon() {
		return appIcon;
	}

	public void setAppIcon(String appIcon) {
		this.appIcon = appIcon;
	}

	public OpenAPIAppRecommendType getAppType() {
		return appType;
	}

	public void setAppType(OpenAPIAppRecommendType appType) {
		this.appType = appType;
	}

	public void setAppStatus(YesNoStatus appStatus) {
		this.appStatus = appStatus;
	}

	public YesNoStatus getAppStatus() {
		return appStatus;
	}

	public void setAppIsOpen(YesNoStatus appIsOpen) {
		this.appIsOpen = appIsOpen;
	}

	public YesNoStatus getAppIsOpen() {
		return appIsOpen;
	}

	public void setAppPrice(Double appPrice) {
		this.appPrice = appPrice;
	}

	public Double getAppPrice() {
		return appPrice;
	}

	public void setAppIsFree(OpenAPIAppRecommendFreeType appIsFree) {
		this.appIsFree = appIsFree;
	}

	public OpenAPIAppRecommendFreeType getAppIsFree() {
		return appIsFree;
	}

	public void setAppSort(Integer appSort) {
		this.appSort = appSort;
	}

	public Integer getAppSort() {
		return appSort;
	}

}
